package sfmc.biz.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import sfmc.biz.dao.SfmcEmpDao;
import sfmc.biz.service.SfmcEmpService;
import sfmc.biz.vo.Sfmc_TB_EMPLOYEE;

@Service("SfmcEmpService")
public class SfmcEmpServiceImpl implements SfmcEmpService{
	
	protected Log log = LogFactory.getLog(this.getClass());
	
	@Resource(name="SfmcEmpDao")
	private SfmcEmpDao sfmcEmpDao;
	
	public void setSfmcEmpDao(SfmcEmpDao sfmcEmpDao) {
		this.sfmcEmpDao = sfmcEmpDao;
	}

	@Override
	public List<Sfmc_TB_EMPLOYEE> getEmpList(Sfmc_TB_EMPLOYEE sfmc_TB_EMPLOYEE){
		
		String where = "";
		
		try{
			if(!"".equals(sfmc_TB_EMPLOYEE.getSearchEmpName())){
				where = "AND A.empName LIKE '%" + sfmc_TB_EMPLOYEE.getSearchEmpName() + "%'\n";
			}
			
			sfmc_TB_EMPLOYEE.setWhere(where);
			return sfmcEmpDao.getEmpList(sfmc_TB_EMPLOYEE);
		}catch(Exception e){
			log.error(e);
			return null;
		}
	}

	@Override
	public int insertEmp(Sfmc_TB_EMPLOYEE dto) {
		
		try{
			sfmcEmpDao.insertEmp(dto);
			return 1;
		}catch(Exception e){
			log.error(e);
			return -1;
		}
	}
	
	@Override
	public int updateEmp(Sfmc_TB_EMPLOYEE dto) {
		try{
			return sfmcEmpDao.updateEmp(dto);
		}catch(Exception e){
			log.error(e);
			return -1;
		}
	}

	@Override
	public int deleteCustomer(Sfmc_TB_EMPLOYEE dto) {
		try{
			return sfmcEmpDao.deleteEmp(dto);
		}
		catch(Exception e){
			log.error(e);
			return -1;
		}
	}
}
